const util = require('../../../../../utils/util.js');
const api = require('../../../../../config/api.js');
const app = getApp();
Page({
  data: {
    //获取用户信息
    logininfo: {},
    //获取用户id
    openid: '',
    //获取访问用户id
    getopenid: '',
    //关注的人集合
    lookmearr: [],
    //页数
    pageNum: 1,
  },
  //加载
  onLoad: function (option) {
    var _this = this
    _this.setData({
      logininfo: app.globalData.logininfo,
      openid: app.globalData.logininfo.openid,
      getOpenid: option.openid,
    });
    if (_this.data.openid == _this.data.getOpenid){
      wx.setNavigationBarTitle({
        title: "谁看过我",
      })
    }else{
      wx.setNavigationBarTitle({
        title: "谁看过Ta",
      })
    }
    var openid = _this.data.getOpenid
    var data = {}
    if (openid != null && openid != "") {
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        data.openid = openid
        data.access_token = res.access_token;
        data.pageNum = 1
        data.pageSize = 20
        util.post(api.GetUserAccessInfo, data).then(function (res) {
          if (res.code == 200) {
            _this.setData({
              lookmearr: res.result.list
            })
            console.log(res.result.list)
          }
        });
      });
    }
  },
  gotohome: function (e) {
    console.log(e)
    var eId = e.target.dataset.id
    wx.redirectTo({
      url: '../personhome?openid='+eId,
    })
  }
})